home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / tests / imgPPM.test < prev    next >
Encoding:
Text File  |  1995-06-09  |  5.8 KB  |  135 lines

  1. # This file is a Tcl script to test out the code in tkImgFmtPPM.c,
  2. # which reads and write PPM-format image files for photo widgets.
  3. # The files is organized in the standard fashion for Tcl tests.
  4. #
  5. # Copyright (c) 1994 Sun Microsystems, Inc.
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10. # @(#) imgPPM.test 1.3 95/06/08 17:04:46
  11.  
  12. if {[info procs test] != "test"} {
  13.     source defs
  14. }
  15.  
  16. foreach i [winfo children .] {
  17.     destroy $i
  18. }
  19. wm geometry . {}
  20. raise .
  21.  
  22. eval image delete [image names]
  23.  
  24. proc put {file data} {
  25.     set f [open $file w]
  26.     puts -nonewline $f $data
  27.     close $f
  28. }
  29.  
  30. test ppm-1.1 {FileReadPPM procedure} {
  31.     put test.ppm "P6\n0 256\n255\nabcdef"
  32.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  33. } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  34. test ppm-1.2 {FileReadPPM procedure} {
  35.     put test.ppm "P6\n-2 256\n255\nabcdef"
  36.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  37. } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  38. test ppm-1.3 {FileReadPPM procedure} {
  39.     put test.ppm "P6\n10 0\n255\nabcdef"
  40.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  41. } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  42. test ppm-1.4 {FileReadPPM procedure} {
  43.     put test.ppm "P6\n10 -2\n255\nabcdef"
  44.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  45. } {1 {PPM image file "test.ppm" has dimension(s) <= 0}}
  46. test ppm-1.5 {FileReadPPM procedure} {
  47.     put test.ppm "P6\n10 10\n255\nabcdef"
  48.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  49. } {1 {error reading PPM image file "test.ppm": not enough data}}
  50. test ppm-1.6 {FileReadPPM procedure} {
  51.     put test.ppm "P6\n5 4\n255\n01234567890123456789012345678901234567890123456789012345678"
  52.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  53. } {1 {error reading PPM image file "test.ppm": not enough data}}
  54. test ppm-1.7 {FileReadPPM procedure} {
  55.     put test.ppm "P6\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  56.     list [catch {image create photo p1 -file test.ppm} msg] $msg \
  57.         [image width p1] [image height p1]
  58. } {0 p1 5 4}
  59.  
  60. catch {image delete p1}
  61. put test.ppm "P6\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  62. image create photo p1 -file test.ppm
  63. test ppm-2.1 {FileWritePPM procedure} {
  64.     list [catch {p1 write foo/bar/baz/gorp} msg] [string tolower $msg] \
  65.         [string tolower $errorCode]
  66. } {1 {foo/bar/baz/gorp: no such file or directory} {posix enoent {no such file or directory}}}
  67. test ppm-2.2 {FileWritePPM procedure} {
  68.     p1 write test2.ppm
  69.     exec cat test2.ppm
  70. } {P6
  71. 5 4
  72. 255
  73. 012345678901234567890123456789012345678901234567890123456789}
  74.  
  75. test ppm-3.1 {ReadPPMFileHeader procedure} {
  76.     catch {image delete p1}
  77.     put test.ppm "#   \n#\n#\nP6\n#\n##\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  78.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  79. } {0 p1}
  80. test ppm-3.2 {ReadPPMFileHeader procedure} {
  81.     catch {image delete p1}
  82.     put test.ppm "P6\n5\n 4                                                                        255\n012345678901234567890123456789012345678901234567890123456789"
  83.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  84. } {0 p1}
  85. test ppm-3.3 {ReadPPMFileHeader procedure} {
  86.     catch {image delete p1}
  87.     put test.ppm "P6\n#                                                                      asdfasdf\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  88.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  89. } {0 p1}
  90. test ppm-3.4 {ReadPPMFileHeader procedure} {
  91.     catch {image delete p1}
  92.     put test.ppm "P6 \n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  93.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  94. } {0 p1}
  95. test ppm-3.5 {ReadPPMFileHeader procedure} {
  96.     catch {image delete p1}
  97.     put test.ppm "P5\n5 4\n255\n01234567890123456789"
  98.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  99. } {0 p1}
  100. test ppm-3.6 {ReadPPMFileHeader procedure} {
  101.     catch {image delete p1}
  102.     put test.ppm "P3\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  103.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  104. } {1 {couldn't recognize data in image file "test.ppm"}}
  105. test ppm-3.7 {ReadPPMFileHeader procedure} {
  106.     catch {image delete p1}
  107.     put test.ppm "P6x\n5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  108.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  109. } {1 {couldn't recognize data in image file "test.ppm"}}
  110. test ppm-3.8 {ReadPPMFileHeader procedure} {
  111.     catch {image delete p1}
  112.     put test.ppm "P6\nxy5 4\n255\n012345678901234567890123456789012345678901234567890123456789"
  113.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  114. } {1 {couldn't recognize data in image file "test.ppm"}}
  115. test ppm-3.9 {ReadPPMFileHeader procedure} {
  116.     catch {image delete p1}
  117.     put test.ppm "P6\n5\n255\n012345678901234567890123456789012345678901234567890123456789"
  118.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  119. } {1 {couldn't recognize data in image file "test.ppm"}}
  120. test ppm-3.10 {ReadPPMFileHeader procedure} {
  121.     catch {image delete p1}
  122.     put test.ppm "P6\n5 4\nzz255\n012345678901234567890123456789012345678901234567890123456789"
  123.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  124. } {1 {couldn't recognize data in image file "test.ppm"}}
  125. test ppm-3.11 {ReadPPMFileHeader procedure} {
  126.     catch {image delete p1}
  127.     put test.ppm "P6\n5 4\n254\n012345678901234567890123456789012345678901234567890123456789"
  128.     list [catch {image create photo p1 -file test.ppm} msg] $msg
  129. } {1 {couldn't recognize data in image file "test.ppm"}}
  130.  
  131.  
  132. catch {exec rm test.ppm}
  133. catch {exec rm test2.ppm}
  134. eval image delete [image names]
  135.